package com.yuelan.apartment.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.yuelan.common.utils.DateUtils;
import com.yuelan.common.utils.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @description: 自动填充字段
 * @Author: ZhaoYi
 * @date: 24-7-5 0:12
 */
@Component
public class MetaHandlerConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "create_time", Date.class, DateUtils.getNowDate());
        this.strictInsertFill(metaObject, "create_by", String.class, SecurityUtils.getUsername());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "update_time", Date.class, DateUtils.getNowDate());
        this.strictUpdateFill(metaObject, "update_by", String.class, SecurityUtils.getUsername());
    }

}
